var DM = {};
/**
 *@description 获取唯一ID
 */
DM.getOnlyID = function() {
	var guid = "";
	for (var i = 1; i <= 32; i++) {
		var n = Math.floor(Math.random() * 16.0).toString(16);
		guid += n;
		if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
			guid += "-";
	}
	return guid;
}
/*DM 通用方法*/
DM.fun = {

	url : {
		//页面地址跳转
		go : function(url, target) {
			var url = this.wrap(url), target = target ? target : document;
			if ( target instanceof jQuery) {
				target.attr("src", url);
			} else {
				target.location = url;
			}

		},
		wrap : function(url) {
			return url + ((url.indexOf("?") == -1) ? "?" : "&") + "s=" + Math.random()
		}
	},
	form : {

		focus : function(str) {//焦点
			return $("#" + str).focus();
		},

		intFocus : function(obj) {//页面初始时焦点
			setTimeout(function() {
				obj.focus();
			}, 100);
		},

		setValue : function(inputs) {
			var inputJson = {
				data : inputs ? inputs : []
			};
			$.each(inputJson.data, function(i, n) {
				$("#" + n.id).val(n.value)
			})
		},
		confirm : function(fn, msg) {//二次确认
			if (window.event) {
				window.event.cancelBubble = true;
			}
			if (window.confirm( msg ? msg : "此操作不能撤销，你确定要执行吗？")) {
				fn()
			}
		},
		//提交表单
		/*
		 dm.Fun.submit("form1",{
		 action:"http://www.163.com",
		 target:"hideframe",
		 data:[
		 {id:"i1",value:"i1"},
		 {id:"i2",value:"i2"}
		 ]
		 })
		 */

		submit : function(formid, par) {

			var _form = $("#" + formid), _par = $.extend({

				action : null,

				data : [],

				target : null

			}, par || {})

			$.each(_par.data, function(i, n) {

				$("#" + n.id).val(n.value)

			})
			if (_par.action) {
				_form.attr("action", _par.action)
			}

			if (_par.target) {
				_form.attr("target", _par.target)
			}

			_form.submit()

		}
	},
	dialog: {
            //模态弹出窗口
            //默认情况弹出模态窗口取消必须{'value':-1}
            open: function (url, par) {
                var _url = DM.fun.url.wrap(url),
                _par = $.extend({
                    width: 600,
                    height: 400,
                    thisobj: null,
                    arg: null,
                    onok: function () { },
                    oncancel: function () { }
                }, par || {}),
                _window;

                _window = window.showModalDialog(_url, _par.arg || {}, "resizable:1;center:1;help:0;status:0;dialogHeight:" + _par.height + "px;dialogWidth:" + _par.width + "px;");

                if (_window && _window.value != -1) {
                    _par.onok(_window, _par.thisobj)
                } else {
                    _par.oncancel(_par.thisobj)
                }

            },
            //关闭弹出模态窗口
            //returnObj  {'value':1,'id':'0'}
            //w 为窗口obj，默认为本窗口
            close: function (returnObj, w) {
                var _returnValue = returnObj || { 'value': -1 },
                _window = w ? w : window;

                _window.returnValue = _returnValue;
                _window.close();

                return _window.returnValue

            },
            //获取模态窗口传递参数
            getArguments: function (w) {
                var _window = _window = w ? w : window;
                return _window.dialogArguments;
            }
        },
        window:{
                open:function(url,par){
                        var _url = Fun.url.wrap(url),
                        _par = $.extend({
                                width:800,
                                height:600,
                                windowname:null
                                },par||{}),
                        _window;
                        _window = window.open (_url,_par.windowname?_par.windowname:"", "height="+_par.height+" width="+_par.width+", toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no");
                        window.setTimeout(function(){
                            _window.focus()
                        },0)
                    },
	            //关闭弹出窗口
	            //w 为窗口obj，默认为本窗口
                 close:function(w){
	                var  _window = w ? w : window;
	                _window.close();

                 }
            }
}

